﻿#include "ColorSystem.h"
#include <Windows.h>
#include <cctype>

//ConsoleColor的完美封装
namespace MyColor {
	void ConsoleColor::setTextWhite(){//设置三色相加，即白色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |
			FOREGROUND_GREEN | FOREGROUND_BLUE);
	}
	void ConsoleColor::setTextRed(){//设置红色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	}
	void ConsoleColor::setTextGreen(){//设置绿色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	}
	void ConsoleColor::setTextBlue(){//设置蓝色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
	}
	void ConsoleColor::setTextYellow(){//设置红色和绿色相加,黄色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |
			FOREGROUND_GREEN);
	}
	void ConsoleColor::setTextPink(){//设置红色和蓝色相加
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |
			FOREGROUND_BLUE);
	}
	void ConsoleColor::setTextBrightBlue(){//设置青色，绿色和蓝色相加，亮蓝色
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |
			FOREGROUND_BLUE);
	}
}

void ColorSystem::changeTextColor (char color)
{
	color = toupper(color);
	switch (color)
	{
		case 'R'://红色
			MyColor::ConsoleColor::setTextRed(); 
			break;
		case 'G'://绿色
			MyColor::ConsoleColor::setTextGreen(); 
			break;
		case 'B'://蓝色
			MyColor::ConsoleColor::setTextBlue(); 
			break;
		case 'Y'://黄色
			MyColor::ConsoleColor::setTextYellow();
			break;
		case 'P'://粉色
			MyColor::ConsoleColor::setTextPink(); 
			break;
		case 'Q'://青色
			MyColor::ConsoleColor::setTextBrightBlue();
			break;
		case 'W'://白色
			MyColor::ConsoleColor::setTextWhite();
			break;
		default://出现其他字符仍为白色
			MyColor::ConsoleColor::setTextWhite();
			break;
	}
}
